<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\api\controller;

use api\api\service\IndexService;
use api\api\service\UserService;
use cmf\controller\RestBaseController;
use think\App;
use think\Db;

class WuliuController extends RestBaseController
{

   public function getwuliu(){
       $data = input();
       $where['status'] = 2;   //已审核通过的需求
       $where['delete_time'] = 0;

//        if ($class_id) {
//            $where['cate_id'] = $class_id;
//        }
       $res = Db::name('deal_move')
           ->where($where)
           ->field('*,FROM_UNIXTIME(create_time,"%c月%d日") as riqi')
           ->order('is_top desc,is_top_time desc,move_id desc')
           ->page($data['page'], 8)
           ->select()
           ->toArray();

       if ($data['page'] == 1) {
           $num = mt_rand(4, 6);
       } else {
           $num = mt_rand(3, 5);
       }

       foreach ($res as $k => $v) {

           if ($v['send_type'] == 1) {
               $res[$k]['send_name'] = '车找货';
           } else {
               $res[$k]['send_name'] = '货找车';
           }
           if ($v['move_type'] == 1) {
               $res[$k]['move_name'] = '零担运输';
           } else {
               $res[$k]['move_name'] = '整车运输';
           }
           if ($v['pay_type'] == 1) {
               $res[$k]['pay_name'] = '预付';
           } else {
               $res[$k]['pay_name'] = ' 到付';
           }
           $car_type = [1 => '制冷冷柜车', 2 => '保温车辆', 3 => '集装箱拖车', 4 => '散货车辆'];
           $res[$k]['car_name'] = $car_type[$v['car_type']];

       }
       if ($res) {
           $this->success('查询成功', $res);
       } else {
           $this->error('已加载全部');
       }
   }
   public function wuliu(){
       $data = input('');
       $userid = $this->getUserId();
//       $publicService = new PublicService();
//       $AreasService = new AreasService();


       $city_id = $this->find_list(array('id' => $data['send_county_id']));
       $province_id = $this->find_list(array('id' => $city_id));
       $data['send_province_id'] = $province_id;
       $data['send_city_id'] = $city_id;

       $endcity_id = $this->find_list(array('id' => $data['end_county_id']));
       $endprovince_id = $this->find_list(array('id' => $endcity_id));
       $data['end_province_id'] = $endprovince_id;
       $data['end_city_id'] = $endcity_id;


       $data['userid'] = $userid;
       $data['create_time'] = time();
//       $shop = Db::name('shop')->where(array('userid' => $userid))->find();
//       $data['shop_id'] = $shop['shop_id'];
//        $this->error(['code' => 202, 'msg' => $data]);
       $id = Db::name('deal_move')->insertGetId($data);
       if (!$id) {
           $this->error("发布失败");
       }
       $this->success("已发布，请耐心等待平台审核!", $id);
   }
    public static function find_list($where)
    {

        $areas_data = Db::name('areas')->where($where)->field('parent_id')->find();
        return $areas_data['parent_id'];
    }
}
